package 动态规划;

import java.util.List;

public class 单词拆分 {
    public boolean wordBreak(String s, List<String> wordDict) {
        int n = s.length();
        //dp[i] 表示 wordDict是否包含 s[0,i-1]
        boolean[] dp = new boolean[n + 1];
        dp[0] = true;
        for (int i = 1; i <=n ; i++) {
            for (int j = 0; j < i; j++) {
                if (dp[j] && wordDict.contains(s.substring(j,i))){
                    dp[i] = true;
                    continue;
                }
            }
        }
        return dp[n];
    }
}
